package com.bolt.auth.admin.api.sys.dto;

import com.bolt.auth.admin.api.sys.entity.PrivilegeEntity;
import com.bolt.convention.data.BaseDTO;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MenuPrivilegeDTO extends BaseDTO {

    private String id;

    private String title;

    private String code;

    private List<MenuDTO> children;

    private Long pid;

    private Integer childrenSize = 0;

    private Integer subPrivilegeSize = 0;

    private Integer level;

    private String menuId;

    private PrivilegeEntity.PrivilegeTypeEnum type;



    public Boolean getIsLeaf() {
        if(this.type == PrivilegeEntity.PrivilegeTypeEnum.URL && this.pid != null){
            children = subPrivilegeSize > 0? new ArrayList <>():null;
            return !(subPrivilegeSize > 0) ;
        }else if(this.type == PrivilegeEntity.PrivilegeTypeEnum.BUTTON){
            children = null;
            return true;
        }else{
            children = new ArrayList <>();
            return false;
        }
    }

}

 